//
//  AutoScrollConflictViewController.m
//  LearnObjectiveC
//
//  Created by 吴可高 on 16/6/15.
//  Copyright © 2016年 吴可高. All rights reserved.
#import "AutoScrollConflictViewController.h"

#import "DescribeView.h"
#import "EvaluateView.h"
#import "ProductView.h"

@interface AutoScrollConflictViewController();
@property (strong, nonatomic) UIScrollView * mainScrollView;
@property (strong, nonatomic) ProductView  *productView;

@property (strong, nonatomic) DescribeView * describeView;
@property (strong, nonatomic) EvaluateView * evaluateView;
@property (strong, nonatomic) UIView * contrainerView;

@end
@implementation AutoScrollConflictViewController

#pragma mark ViewController LifeCycle
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setObjectView];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.tabBarController.tabBar setHidden:YES];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.tabBarController.tabBar setHidden:NO];
}

#pragma mark ViewController AsynRequestData
-(void)accountInfoAsynRequest;
{

}
#pragma mark ViewController Algorithm Processor
- (void) reverseSourceData:(id)parameter;
{

}

#pragma mark ViewController Initialize SubObjectView
-(void)setObjectView
{
    [self.view addSubview:self.mainScrollView];
    __weak __typeof(self)weakSelf = self;
    [_mainScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        UIEdgeInsets insets = UIEdgeInsetsMake(kNavigationBarHeight, 0, 0 ,0);
        make.edges.mas_equalTo(weakSelf.view).with.insets(insets);
    }];
    [self.mainScrollView addSubview:self.contrainerView];
    [self.contrainerView mas_makeConstraints:^(MASConstraintMaker *make) {
        UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 0, 0);
        make.edges.mas_equalTo(weakSelf.mainScrollView).with.insets(insets);
        make.height.mas_equalTo(weakSelf.mainScrollView.mas_height).with.offset(-10.f);
    }];
    NSArray * mainScrollViews = @[self.productView,self.describeView,self.evaluateView];
    __block UIView * lastView = nil;
    [mainScrollViews enumerateObjectsUsingBlock:^(UIView * subView, NSUInteger idx, BOOL * stop) {
        [self.contrainerView addSubview:subView];
        [subView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.and.bottom.mas_equalTo(weakSelf.contrainerView);
            make.width.mas_equalTo(weakSelf.mainScrollView.mas_width).offset(0);
            if (lastView) {
                make.left.mas_equalTo(lastView.mas_right).with.offset(0.f);
            }
            else
            {
                make.left.mas_equalTo(weakSelf.contrainerView.mas_left).with.offset(0.f);
            }
        }];
        lastView = subView;
    }];
    
    [self.contrainerView mas_updateConstraints:^(MASConstraintMaker *make) {
         make.right.mas_equalTo(lastView.mas_right).with.offset(1.f);
    }];
}

#pragma mark --viewController getter methods
-(UIView *)contrainerView
{
    _contrainerView = ({
        if (!_contrainerView) {
            _contrainerView  = [UIView new];
            _contrainerView.backgroundColor  = [UIColor whiteColor];
            _contrainerView.layer.masksToBounds = YES;
            _contrainerView.layer.cornerRadius  =2.f;
        }
        _contrainerView;
    });
    return _contrainerView;
}

-(UIScrollView *)mainScrollView
{
    _mainScrollView = ({
        if (!_mainScrollView) {
            _mainScrollView  = [[UIScrollView alloc]init];
            _mainScrollView.bounces = NO;
            _mainScrollView.pagingEnabled = YES;
        }
        _mainScrollView;
    });
    return _mainScrollView;
}
- (DescribeView *)describeView
{
    _describeView = ({
        if (!_describeView) {
            _describeView = [DescribeView  new];
        }
        _describeView;
    });
    return _describeView;
}

- (EvaluateView *)evaluateView
{
    _evaluateView = ({
        if (!_evaluateView) {
            _evaluateView =  [EvaluateView new];
        }
        _evaluateView;
    });
    return _evaluateView;
}

- (ProductView *)productView
{
     _productView = ({
        if (!_productView) {
            _productView  = [[ProductView alloc]init];
        }
        _productView;
    });
    return _productView;
}
#pragma mark Possess  Delegate ViewController（委托代理者）
#pragma mark IBOutlet Action ViewController

#pragma mark Other Method
-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
}
@end
